package com.yanfan.modbus.frame;


import com.yanfan.modbus.exception.ModbusTransportException;
import com.yanfan.modbus.frame.abs.ModbusRequest;
import io.netty.buffer.ByteBuf;

/**
 * @author oliver foo
 * @description
 * @date 2022/3/15 17:12
 */
public class ExceptionRequest extends ModbusRequest {
    private final byte functionCode;
    private final byte exceptionCode;


    public ExceptionRequest(int slaveId, byte functionCode, byte exceptionCode) throws ModbusTransportException {
        super(slaveId);
        this.functionCode = functionCode;
        this.exceptionCode = exceptionCode;
    }

    @Override
    public void validate() {
        // no op
    }

    @Override
    protected void writeRequest(ByteBuf buf) {
//        throw new ShouldNeverHappenException("wha");
    }

    @Override
    protected void readRequest(ByteBuf buf) {
//       ReferenceCountUtil.release(queue);
//       queue.clear();
        buf.clear();
    }

    @Override
    public byte getFunctionCode() {
        return functionCode;
    }


    public byte getExceptionCode() {
        return exceptionCode;
    }
}
